package code.part02_objectOriented;

/**
 * @author: ZJT
 * @Time: 2021/7/7
 * @Description: 静态修饰
 */
public class P02_Static {

    String name = "zhangsan";
    static int age = 10;

    public static void test() {
//        test2();//Non-static method 'test2()' cannot be referenced from a static context
//        static int a = 10;//Modifier 'static' not allowed here
    }

    public void test2() {
        System.out.println("non-static");
    }

    public static void main(String[] args) {
        P02_Static s = new P02_Static();
        //使用对象进行调用
        System.out.println(s.age);//10

        s.age = 20;
        System.out.println(s.age);//20
        System.out.println(P02_Static.age);//20

        P02_Static s1 = new P02_Static();
        System.out.println(s1.name);
//        System.out.println(P02_Static.name);//Non-static field 'name' cannot be referenced from a static context

        P02_Static sd = new P02_Static();
        sd.test();
        P02_Static.test();
        sd.test2();


    }
}
